package net.borderwars.util;

import java.io.*;

/**
 * @author ehubbard
 *         Date: Mar 7, 2006
 *         Time: 4:27:55 PM
 */
public class OurBase64 {

    private OurBase64 () {
    }

    static public Object decodeObject (final byte data[]) throws IOException, ClassNotFoundException {
        ByteArrayInputStream baoi = new ByteArrayInputStream (data);
        ObjectInputStream ois = new ObjectInputStream (baoi);
        Object rtn = ois.readObject ();
        return (rtn);
    }

    static public Object decodeObject (final String data) throws IOException, ClassNotFoundException {
        byte bData[] = Base64.decode (data);
        return (decodeObject (bData));

    }

    static public String encodeObject (Object o) throws IOException {
        ByteArrayOutputStream baos = new ByteArrayOutputStream ();
        ObjectOutputStream oos = new ObjectOutputStream (baos);
        oos.writeObject (o);
        byte data[] = baos.toByteArray ();
        String rtn = Base64.encodeBytes (data);
        return (rtn);
    }
}
